package day11;
//测试 字符串拼接工具类
public class Test3_StringBuffer {
    public static void main(String[] args) {
//        method();//用+拼接
        method2();//用工具类拼接
    }
    public static void method2() {
        String s = "abcdefg" ;
//        StringBuilder sb = new StringBuilder();
        StringBuffer sb = new StringBuffer();

        long start = System.currentTimeMillis() ;//计时开始
        for (int i = 0; i < 100000; i++) {
            sb.append(s);//利用工具追加数据
        }
        long end = System.currentTimeMillis() ;//计时结束
        System.out.println(end-start);//9ms
    }
    public static void method() {
        String s = "abcdefg" ;
        String res = "" ;//定义变量,记录拼接结果

        long start = System.currentTimeMillis() ;//计时开始
        for (int i = 0; i < 100000; i++) {
            res = res + s ;//通过+拼接字符串
        }
        long end = System.currentTimeMillis() ;//计时结束
        System.out.println(end-start);//50277ms
    }
}
